package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class PlanDialogAdapter extends AppAdapter<String> {
    private int selPosition = -1;
    public PlanDialogAdapter(Context context) {
        super(context);
    }

//    @Override
//    public int getItemCount() {
//        return 10;
//    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvItem;



        private ViewHolder() {
            super(R.layout.item_plan);
            mTvItem = findViewById(R.id.tv_item);
        }

        @Override
        public void onBindView(int position) {
            mTvItem.setText(getItem(position));
            if (position == selPosition) {
                setTag(position);
                mTvItem.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF4FF))
                        .intoBackground();
                mTvItem.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_4181fe))
                        .intoTextColor();
            } else {
                mTvItem.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_F5F5F5))
                        .intoBackground();
                mTvItem.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_151515))
                        .intoTextColor();
            }
        }
    }
    public void setItemSel(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }
}